package com.wuming.house.service.impl;

import com.wuming.house.dao.BrowseRecordMapper;
import com.wuming.house.model.BrowseRecord;
import com.wuming.house.service.BrowseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuhuai
 * @createTime 2019/9/17 10:49
 * @Description:
 */
@Service
public class BrowseRecordServiceImpl extends BaseServiceImpl implements BrowseRecordService {

    @Autowired
    private BrowseRecordMapper browseRecordMapper;

    @Override
    public List<BrowseRecord> getBrowseRecordByPage(Long userid, Integer houseType, int pageIndex, int pageSize) {
        Map<String,Object> params = new HashMap<>();
        if (null!=userid){
            params.put("userid",userid);
        }
        if (null!=houseType){
            params.put("houseType",houseType);
        }
        try {
            return (List<BrowseRecord>) this.getPageList(BrowseRecordMapper.class,"selectByParams",params,pageIndex,pageSize);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getTotal(Long userid, Integer houseType) {
        Map<String,Object> params = new HashMap<>();
        if (null!=userid){
            params.put("userid",userid);
        }
        if (null!=houseType){
            params.put("houseType",houseType);
        }
        try {
            return this.getTotal(BrowseRecordMapper.class,"selectTotal",params);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public BrowseRecord getBrowseRecordByParams(Long houseId, Long userid, Integer houseType) {
        Map<String,Object> params = new HashMap<>();
        if (null!=houseId){
            params.put("houseId",houseId);
        }
        if (null!=userid){
            params.put("userid",userid);
        }
        if (null!=houseType){
            params.put("houseType",houseType);
        }
        try {
            return browseRecordMapper.selectBrByParams(params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void saveBrowseRecord(BrowseRecord browseRecord) {
        try {
            browseRecordMapper.insert(browseRecord);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void modifyBrowseRecord(BrowseRecord browseRecord) {
        try {
            browseRecordMapper.updateByPrimaryKey(browseRecord);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
